package com.java110.mall.goods.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.shop.ShopAppraiseDto;
import com.java110.po.shop.ShopAppraisePo;
import com.java110.mall.goods.bmo.shopAppraise.IDeleteShopAppraiseBMO;
import com.java110.mall.goods.bmo.shopAppraise.IGetShopAppraiseBMO;
import com.java110.mall.goods.bmo.shopAppraise.IUpdateShopAppraiseBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/shopAppraise")
public class ShopAppraiseApi {

    @Autowired
    private IUpdateShopAppraiseBMO updateShopAppraiseBMOImpl;
    @Autowired
    private IDeleteShopAppraiseBMO deleteShopAppraiseBMOImpl;

    @Autowired
    private IGetShopAppraiseBMO getShopAppraiseBMOImpl;


    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopAppraise/updateShopAppraise
     * @path /app/shopAppraise/updateShopAppraise
     */
    @RequestMapping(value = "/updateShopAppraise", method = RequestMethod.POST)
    public ResponseEntity<String> updateShopAppraise(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "context", "请求报文中未包含context");
        Assert.hasKeyAndValue(reqJson, "appraiseId", "appraiseId不能为空");


        ShopAppraisePo shopAppraisePo = BeanConvertUtil.covertBean(reqJson, ShopAppraisePo.class);
        return updateShopAppraiseBMOImpl.update(shopAppraisePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopAppraise/deleteShopAppraise
     * @path /app/shopAppraise/deleteShopAppraise
     */
    @RequestMapping(value = "/deleteShopAppraise", method = RequestMethod.POST)
    public ResponseEntity<String> deleteShopAppraise(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "appraiseId", "appraiseId不能为空");


        ShopAppraisePo shopAppraisePo = BeanConvertUtil.covertBean(reqJson, ShopAppraisePo.class);
        return deleteShopAppraiseBMOImpl.delete(shopAppraisePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 商铺ID
     * @return
     * @serviceCode /shopAppraise/queryShopAppraise
     * @path /app/shopAppraise/queryShopAppraise
     */
    @RequestMapping(value = "/queryShopAppraise", method = RequestMethod.GET)
    public ResponseEntity<String> queryShopAppraise(@RequestParam(value = "shopId") String shopId,
                                                    @RequestParam(value = "objId", required = false) String objId,
                                                    @RequestParam(value = "prodName", required = false) String prodName,
                                                    @RequestParam(value = "objType", required = false) String objType,
                                                    @RequestParam(value = "appraiseUserName", required = false) String appraiseUserName,
                                                    @RequestParam(value = "appraiseScore", required = false) String appraiseScore,
                                                    @RequestParam(value = "page") int page,
                                                    @RequestParam(value = "row") int row) {
        ShopAppraiseDto shopAppraiseDto = new ShopAppraiseDto();
        shopAppraiseDto.setPage(page);
        shopAppraiseDto.setRow(row);
        shopAppraiseDto.setShopId(shopId);
        shopAppraiseDto.setObjId(objId);
        shopAppraiseDto.setProdName(prodName);
        shopAppraiseDto.setAppraiseUserName(appraiseUserName);
        shopAppraiseDto.setAppraiseScore(appraiseScore);
        shopAppraiseDto.setObjType(objType);
        return getShopAppraiseBMOImpl.get(shopAppraiseDto);
    }
}
